﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;

namespace PizzaService.BindValidation
{

    /// <summary>
    /// Hausnummer
    /// </summary>
    class ValidateHouseNumber : ValidationRule
    {
        public override ValidationResult Validate(object value, System.Globalization.CultureInfo cultureInfo)
        {
            string tempS = (string)value;

            int letterCounter = 0;

            foreach (char s in tempS)
            {
                if (Char.IsWhiteSpace(s))
                    return new ValidationResult(false, "Keine Leerzeichen erlaubt");

                if (Char.IsLetter(s))
                    letterCounter++;

                if (letterCounter >= 2)
                    return new ValidationResult(false, "Mehr als 1 Buchstabe ist nicht erlaubt");
            }

            return ValidationResult.ValidResult;
        }
    }
}
